# Created by Gigiikun
# Update by pmq 16-09-2010

import sys
from com.l2jserver import Config
from com.l2jserver.gameserver.model.quest import State
from com.l2jserver.gameserver.model.quest import QuestState
from com.l2jserver.gameserver.model.quest.jython import QuestJython as JQuest

qn = "643_RiseandFalloftheElrokiTribe"
#Npc
Singsing = 32106
Karakawei = 32117
#Settings: drop chance in %
DROP_CHANCE = 75
#Mobs
PLAIN_DINOSAURS = [22200,22201,22202,22219,22203,22204,22205,22220,22208,22209,22210,22211,22212,22213,22221,22222,22226,22227]
#Item
BONES_OF_A_PLAINS_DINOSAUR = 8776
REWARDS = range(8712,8723)
# Singsing npc Html
# 32106-00
Singsing_A = "<html><body>辛刑：<br>啊~冒险家啊~在找寻可做的事情吗？这次这里发现原始之岛，亚丁港口在这里开设了一个码头。<br>找寻这地方的冒险家渐渐增加，关心这里的魔法师也逐渐增加。<br>我们除了准备船只，也提供便利的服务给来访此地的人，而且也与原住民交易。<br>现在提供冒险家们与委托者们的联系业务。<br>对了。现在有收到一个委托...<br>哦...<br>看来这委托对冒险家您有点困难喔。<br>(只有达到等级75以上才能执行任务。)</body></html>"
# 32106-01
Singsing_B = "<html><body>辛刑：<br>啊~冒险家啊~在找寻可做的事情吗？这次这里发现原始之岛，亚丁港口在这里开设了一个码头。<br>找寻这地方的冒险家渐渐增加，关心这里的魔法师也逐渐增加。<br>我们除了准备船只，也提供便利的服务给来访此地的人，而且也与原住民交易。<br>同时也提供冒险家们与委托者们的联系业务。<br>对了。现在有收到一个委托...<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_C\">是什么委托呢？</a></body></html>"
# 32106-02
Singsing_C = "<html><body>辛刑：<br>在这原始之岛栖息着太古的生物-恐龙，是在亚丁大陆看不到的。有知识的魔法师们说因为连诸神都怕它们强悍的力量，因此曾与巨人并肩作战过。因某种原因在亚丁大陆已经消失的这些生物竟在此地被发现了。<br>在码头附近只有发现比较微弱的生物，<br>叫做毕菲格的魔法师说为了研究需要此生物的骨头。如果击败恐龙带回它的骨头，我将它购买转达给委托人。您要接受委托吗？<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_D\">区区那种小事...我很乐意帮您</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_I\">不好意思...我对爬虫类有恐惧症...对不起</a></body></html>"
# 32106-03
Singsing_D = "<html><body>辛刑：<br>啊，果然是个冒险家啊。狩猎<font color=\"LEVEL\">恐爪龙、似鸟龙、厚头龙、野生座龙</font>们之后，拿回<font color=\"LEVEL\">平原恐龙的骨头</font>我就会转达给毕菲格。<br>对了，与这岛的原住民交易的朋友说，原住民的咒术士也在寻找这恐龙的骨头。如果您有兴趣去见原住民咒术士吧。<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_E\">原住民咒术士所在的位置是？</a></body></html>"
# 32106-04
Singsing_E = "<html><body>辛刑：<br>原住民的咒术士在此地南方的原始之平原南部有一个孤岛。因为排斥外来者，所以只能透过原始平原南部海岸与失落的巢穴之间的山麓角落，叫做<font color=\"LEVEL\">欧拉奇恩</font>的原住民战士才能进入那孤岛。</body></html>"
# 32106-05
Singsing_F = "<html><body>辛刑：<br>赶快把恐龙的骨头收集回来吧，毕菲格一直在催呢。<br>好像是因为没有恐龙的骨头无法进行研究...<br>说是即将要在米兹巴帝魔法协会发表研究内容呢。<br>请您再多努力！<br>狩猎<font color=\"LEVEL\">恐爪龙、似鸟龙、厚头龙、野生座龙</font>们之后，拿回<font color=\"LEVEL\">平原恐龙的骨头</font>就可以了。</body></html>"
# 32106-05a
Singsing_G = "<html><body>辛刑：<br>哦！您收回<font color=\"LEVEL\">平原恐龙的骨头</font>啦。收集回来的<font color=\"LEVEL\">平原恐龙的骨头</font>，对毕菲格的研究会有很大的帮助。<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_H\">将收回的平原恐龙的骨头交换成金币</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_J\">说“将收集到的平原恐龙的骨头直接交给原住民咒术士”</a></body></html>"
# 32106-06
Singsing_H = "<html><body>辛刑：<br>啊，这个我会好好收藏。一定会转达给毕菲格的。毕菲格一定会很喜欢。<br>这是委托的费用。虽然不多但也请您收下。<br>要继续接受委托吗？<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_L\">继续工作</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_I\">不做了</a></body></html>"
# 32106-07
Singsing_I = "<html><body>辛刑：<br>啊，是吗。对冒险家您来说，这座岛好像不是个令您舒服的地方。这里有很多您讨厌的爬虫类出没喔... (这样也叫冒险家啊？)</body></html>"
# 32106-08
Singsing_J = "<html><body>辛刑：<br>啊~原来这样啊...哦...把<font color=\"LEVEL\">平原恐龙的骨头</font>交给谁其实是冒险家您自己可做的决定...但是哪边比较有利请您重新考虑一下。<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_E\">原住民咒术士在哪里？</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Singsing_K\">透过原住民咒术士可以得到些什么？</a><br></body></html>"
# 32106-08a
Singsing_K = "<html><body>辛刑：<br>听说向原住民的咒术士们交付平原恐龙的骨头300个的话，就能随机得到<font color=\"LEVEL\">为了制作A级特级武器的材料</font>。<br>而且，最近还说是会给<font color=\"LEVEL\">S80卷轴</font>作为奖励品呢。这些东西依照物品将会要求平原恐龙的骨头100~300个左右。<br>但是，如果透过我的话，就不需经过麻烦的手续，只要以<font color=\"LEVEL\">金币</font>就能交换了。所以请您慎重考虑，别做出让自己后悔的选择。</body></html>"
# 32106-09
Singsing_L = "<html><body>辛刑：<br>那麻烦您继续努力。狩猎<font color=\"LEVEL\">恐爪龙、似鸟龙、厚头龙、野生座龙</font>之后，拿回<font color=\"LEVEL\">平原恐龙的骨头</font>就可以了。</body></html>"
# Singsing npc Html
# 32117-01
Karakawei_A = "<html><body>卡拉卡维：<br>据说我们一族是为了监视连神都会惧怕的太古强力生命体-恐龙，伟大的女神席琳所挑选出的坚强种族。但是不知从何时起席琳对我们的祈祷没有回应。<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_B\">询问为什么没有回应</a></body></html>"
# 32117-02
Karakawei_B = "<html><body>卡拉卡维：<br>那个我们也不太清楚。难道我们一族有做到什么不忠的事情吗？不管怎样，我们种族一定要恢复席琳的恩宠。失去恩宠的我们一族变的越来越懦弱...生病...还被我们所监视的恐龙击败...种族本身渐渐衰竭。<br>外来的冒险家啊，我们为了治愈我们渐渐深重的病，以及为了举行恢复席琳之恩宠的仪式，需要祭品...<br>为了我们，你可以捐出<font color=\"LEVEL\">平原恐龙的骨头</font>吗？如果协助我们完成恢复恩宠的仪式，那么我会给你们用于制作武器的材料，而为了治疗病情协助我们制作药材的话，我会给你用于制作武器的制作卷轴来报答你。<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_D\">请将平原恐龙的骨头300个用于“祭祀”上</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_F\">请将平原恐龙的骨头用为“药材”</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_H\">对你们那原始种族的兴亡没什么兴趣，随你便吧</a></body></html>"
# 32117-02a
Karakawei_C = "<html><body>卡拉卡维：<br>是那时候的冒险家啊...你来找我们一族是为何事？<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_A\">询问有关耶尔可罗一族的兴盛衰亡</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_D\">请将平原恐龙的骨头300个用于“祭祀”上</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_F\">请将平原恐龙的骨头用为“药材”</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe Karakawei_H\">对你们那原始种族的兴亡没什么兴趣随你便吧</a></body></html>"
# 32117-03
Karakawei_D = "<html><body>卡拉卡维：<br>Thank you, adventurer...<br>I can now perform the ritual.<br>(Karakawei softly chants and seems to lose consciousness.)<br>....<br>....<br>....<br>....<br>(Suddenly, his eyes open!)<br>Ah, I feel that Shilen is satisfied with the ritual!<br>Thank you, adventurer...<br>Please accept this as a token of our appreciation. I also ask that you bring back those bones of the dinosaurs from the plains so that we may continue with these rituals!</body></html>"
# 32117-04
Karakawei_E = "<html><body>卡拉卡维：<br>为了祭祀需要<font color=\"LEVEL\">300个平原恐龙的骨头</font>。如果将祭祀疏忽了事，不用说是得到席琳的恩宠，可能会受到灾难！！！<br>快点去狩猎<font color=\"LEVEL\">恐爪龙、似鸟龙、厚头龙、野生座龙</font>之后，带回<font color=\"LEVEL\">平原恐龙的骨头300个</font>回来！！！</body></html>"
# 32117-05
Karakawei_F = "<html><body>卡拉卡维：<br>如果为了治疗我们的病，捐出平原恐龙的骨头的话，我会按照那个数量支付你合理的酬劳。<br>你想要选择什么呢？<br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe 1\">捐出平原恐龙的骨头400个后，领取“制作卷轴-封印的王朝外衣（60%）”</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe 2\">捐出平原恐龙的骨头250个后，领取“制作卷轴-封印的王朝长袜（60%）”</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe 3\">捐出平原恐龙的骨头200个后，领取“制作卷轴-封印的王朝头箍（60%）”</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe 4\">捐出平原恐龙的骨头134个后，领取“制作卷轴-封印的王朝手套（60%）”</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe 5\">捐出平原恐龙的骨头134个后，领取“制作卷轴-封印的王朝鞋（60%）”</a><br><a action=\"bypass -h Quest 643_RiseandFalloftheElrokiTribe 6\">捐出平原恐龙的骨头287个后，领取“制作卷轴-封印的王朝符印（60%）”</a></body></html>"
# 32117-06
Karakawei_G = "<html><body>卡拉卡维：<br>为了制作药剂，需要用到足够的平原恐龙的骨头。我们不是为了利益，而是为了生存才会进行交易的，因此，休想与我们讨价还价。如果没有确保正确的数量，那就没有所谓的交易。<br>赶快去狩猎<font color=\"LEVEL\">恐爪龙、似鸟龙、厚头龙、野生座龙</font>之后，收集足够的<font color=\"LEVEL\">平原恐龙的骨头</font>回来！！！</body></html>"
# 32117-08
Karakawei_H = "<html><body>卡拉卡维：<br>哦...是个嚣张的外来者...如果能恢复我们种族从前的力量...就不会受到这种待遇...<br>啊，啊，席琳啊...<br>如果没事赶快离开这里！！！</body></html>"

class Quest (JQuest) :

	def __init__(self,id,name,descr):
		JQuest.__init__(self,id,name,descr)
		self.questItemIds = [BONES_OF_A_PLAINS_DINOSAUR]

	def onAdvEvent (self,event,npc,player) :
		htmltext = event
		st = player.getQuestState(qn)
		if not st : return

		count = st.getQuestItemsCount(BONES_OF_A_PLAINS_DINOSAUR)
		if event == "Singsing_D" :
			htmltext = Singsing_D
			st.set("cond","1")
			st.setState(State.STARTED)
			st.playSound("ItemSound.quest_accept")
		elif event == "Singsing_H" :
			htmltext = Singsing_H
			st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,-1)
			st.giveItems(57,count*1374)
		elif event == "Singsing_I" :
			htmltext = Singsing_I
			st.playSound("ItemSound.quest_finish")
			st.exitQuest(1)
		elif event == "Karakawei_D" :
			if count >= 300 :
				st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,300)
				st.rewardItems(REWARDS[self.getRandom(len(REWARDS))],5)
				htmltext = Karakawei_D
			else :
				htmltext = Karakawei_E
		elif event == "1" :
			if count >= 400 :
				st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,400)
				st.giveItems(9492,1)
				htmltext = Karakawei_F
			else :
				htmltext = Karakawei_G
		elif event == "2" :
			if count >= 250 :
				st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,250)
				st.giveItems(9493,1)
				htmltext = Karakawei_F
			else :
				htmltext = Karakawei_G
		elif event == "3" :
			if count >= 200 :
				st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,200)
				st.giveItems(9494,1)
				htmltext = Karakawei_F
			else :
				htmltext = Karakawei_G
		elif event == "4" :
			if count >= 134 :
				st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,134)
				st.giveItems(9495,1)
				htmltext = Karakawei_F
			else :
				htmltext = Karakawei_G
		elif event == "5" :
			if count >= 134 :
				st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,134)
				st.giveItems(9496,1)
				htmltext = Karakawei_F
			else :
				htmltext = Karakawei_G
		elif event == "6" :
			if count >= 287 :
				st.takeItems(BONES_OF_A_PLAINS_DINOSAUR,287)
				st.giveItems(10115,1)
				htmltext = Karakawei_F
			else :
				htmltext = Karakawei_G
		elif event == "Singsing_A" :
			htmltext = Singsing_A
		elif event == "Singsing_B" :
			htmltext = Singsing_B
		elif event == "Singsing_C" :
			htmltext = Singsing_C
		elif event == "Singsing_D" :
			htmltext = Singsing_D
		elif event == "Singsing_E" :
			htmltext = Singsing_E
		elif event == "Singsing_F" :
			htmltext = Singsing_F
		elif event == "Singsing_G" :
			htmltext = Singsing_G
		elif event == "Singsing_H" :
			htmltext = Singsing_H
		#elif event == "Singsing_I" :
		#	htmltext = Singsing_I
		elif event == "Singsing_J" :
			htmltext = Singsing_J
		elif event == "Singsing_K" :
			htmltext = Singsing_K
		elif event == "Singsing_L" :
			htmltext = Singsing_L
		elif event == "Karakawei_A" :
			htmltext = Karakawei_A
		elif event == "Karakawei_B" :
			htmltext = Karakawei_B
		elif event == "Karakawei_C" :
			htmltext = Karakawei_C
		elif event == "Karakawei_D" :
			htmltext = Karakawei_D
		elif event == "Karakawei_E" :
			htmltext = Karakawei_E
		elif event == "Karakawei_F" :
			htmltext = Karakawei_F
		elif event == "Karakawei_G" :
			htmltext = Karakawei_G
		elif event == "Karakawei_H" :
			htmltext = Karakawei_H
		return htmltext

	def onTalk (self,npc,player):
		htmltext = "<html><body>目前没有执行任务，或条件不符。</body></html>"
		st = player.getQuestState(qn)
		if not st: return htmltext

		npcId = npc.getNpcId()
		id = st.getState()
		cond = st.getInt("cond")

		count = st.getQuestItemsCount(BONES_OF_A_PLAINS_DINOSAUR)
		if id == State.CREATED :
			if npcId == 32106 and cond == 0 :
				if player.getLevel() >= 75 :
					htmltext = Singsing_B
				else :
					htmltext = Singsing_A
					st.exitQuest(1)
		elif id == State.STARTED :
			if npcId == 32106 and cond == 1 :
				if count == 0 :
					htmltext = Singsing_F
				else :
					htmltext = Singsing_G
			elif npcId == 32117 and cond == 1 :
				if count == 0 :
					htmltext = Karakawei_A
				else :
					htmltext = Karakawei_C
		return htmltext

	def onKill (self, npc, player,isPet):
		partyMember = self.getRandomPartyMember(player,"1")
		if not partyMember: return
		st = partyMember.getQuestState(qn)
		if st :
			if st.getState() == State.STARTED :
				npcId = npc.getNpcId()
				cond = st.getInt("cond")
				count = st.getQuestItemsCount(BONES_OF_A_PLAINS_DINOSAUR)
				if cond == 1 :
					chance = DROP_CHANCE*Config.RATE_QUEST_DROP
					numItems, chance = divmod(chance,100)
					if self.getRandom(100) < chance : 
						numItems += 1
					if numItems :
						st.playSound("ItemSound.quest_itemget")
						st.giveItems(BONES_OF_A_PLAINS_DINOSAUR,int(numItems))
		return

QUEST		= Quest(643,qn,"耶尔可罗一族的兴盛衰亡")

QUEST.addStartNpc(32106)

QUEST.addTalkId(32106)
QUEST.addTalkId(32117)

for mob in PLAIN_DINOSAURS :
	QUEST.addKillId(mob)